package com.xundao.yxt.common.util;

import com.xundao.yxt.common.constants.CoreConst;
import com.xundao.yxt.common.vo.base.PageResultVo;
import com.xundao.yxt.common.vo.base.ResponseVo;

import java.util.ArrayList;
import java.util.List;

public class ResultUtils {
    public static <T> ResponseVo<T> success() {
        return vo(CoreConst.SUCCESS_CODE, null, null);
    }

    public static  <T> ResponseVo<T> success(String msg) {
        return vo(CoreConst.SUCCESS_CODE, msg, null);
    }

    public static  <T> ResponseVo<T> success(String msg, T data) {
        return vo(CoreConst.SUCCESS_CODE, msg, data);
    }

    public static  <T> ResponseVo<T> error() {
        return vo(CoreConst.FAIL_CODE, null, null);
    }

    public static  <T> ResponseVo<T> error(String msg) {
        return vo(CoreConst.FAIL_CODE, msg, null);
    }

    public static  <T> ResponseVo<T> error(String msg, T data) {
        return vo(CoreConst.FAIL_CODE, msg, data);
    }

    public static <T> PageResultVo<T> table(List<T> list, Long total) {
        if (list == null) {
            list = new ArrayList<>();
        }
        if (total == null) {
            total = 0L;
        }
        return new PageResultVo<>(list, total);
    }

    public static  <T> ResponseVo<T> vo(Integer status, String message, T data) {
        return new ResponseVo<>(status, message, data);
    }
}
